//
//  DemoRoot.swift
//  soapp
//
//  Created by zhu xietong on 2017/9/5.
//  Copyright © 2017年 CocoaPods. All rights reserved.
//

import Foundation
import Eelay
import JoLoading
import soapp


func __demoStyle()->EeTopStyle{
    var style = EeTopStyle()
    style.navTintColor = UIColor(red: 0, green: 0.478431, blue: 1, alpha: 1.0)
    style.statusBarStyle = .default
    style.navBarBgAlpha = 0
    return style
}





class DemoListCtr: ListController {
    override var initTopStyle: EeTopStyle{
        get{
            var style = EeTopStyle()
            style.navTintColor = .blue
            style.statusBarStyle = .lightContent
            style.navBarBgStyle = .color(UIColor(shex: "#3333"))
            style.navBarBgAlpha = 0
            style.navBarShadow = .none
            style.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.blue]
            return style
            
        }
    }
    let section:TP.section = [
        [
            ["name":"Base"],
            ["name":"FormDemo"],
            ["name":"TableConfig"],
            ["name":"PaginatorCtr"],
            ["name":"LoadingCtr"],
            ["name":"nav"],
            ["name":"SideDemoCtr"],
            ["name":"DropMenu"],
            ["name":"alert"],
            ["name":"ASTabcontainerDemo"],
            ["name":"ASListControllerDemo"],
            ["name":"ASColListControllerDemo"],
            ["name":"ASViewControllerDemo"],
            ["name":"DownloadTasksCtr"],
            ["name":"webController"]
        ]
    ]
    let selector:TP.selector =  [
        "<default>":Cell.self,
    ]
    
//    let down = DownloadTask("http://test.doncheng.cn/public/attachment/video/20190228/9184c60644692aeba61bebdd77fdd9a2.mp4")
    override func viewDidLoad() {
        
//        task1.progress = {
//            status in
//            print("====ooooo|\(status)")
//        }
//        
//        task1.begin()
        
        

        title = "demo"
        super.viewDidLoad()
        tableView.buildDynamicHeight(height: 40)
        
//        var style = EeTopStyle()
//        style.navTintColor = .blue
//        style.statusBarStyle = .lightContent
//        style.navBarBgStyle = .color(UIColor(shex: "#3333"))
//        style.navBarBgAlpha = 0
//        style.navBarShadow = .none
//        style.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.blue]
        
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Goosd", style: .plain, target: nil, action: nil)

        tableView.load(sections: section, selector: selector)
        
        
    }
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        self.navigationController?.navigationBar.shadowImage = UIImage()
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        guard let data = tableView.cellData(at: indexPath) else {return}
        switch data["name",""] {
        case "TableConfig":
            let ctr = DetailCtr()
            self.navigationController?.pushViewController(ctr, animated: true)
        case "PaginatorCtr":
            self.navigationController?.pushViewController(PaginatorCtr(), animated: true)
        case "LoadingCtr":
            self.navigationController?.pushViewController(LoadingCtr(), animated: true)
        case "SideDemoCtr":
            let ctr = SideDemoCtr()
            self.present(ctr, animated: false, completion: nil)
        case "alert":
            InfoAlert().show()
        case "ASTabcontainerDemo":
            let ctr = ASTabcontainerDemo()
            self.navigationController?.pushViewController(ctr, animated: true)
        case "ASListControllerDemo":
            let ctr = ASListControllerDemo()
            self.navigationController?.pushViewController(ctr, animated: true)
        case "ASColListControllerDemo":
            let ctr = ASColListControllerDemo()
            self.navigationController?.pushViewController(ctr, animated: true)
        case "ASViewControllerDemo":
            let ctr = ArtController()
            self.navigationController?.pushViewController(ctr, animated: true)
        case "DropMenu":
            let ctr = SideDemoCtr()
            self.navigationController?.pushViewController(ctr, animated: true)
        case "FormDemo":
            let ctr = FormDemo()
            self.navigationController?.pushViewController(ctr, animated: true)
        case "DownloadTasksCtr":
            let ctr = DownloadTasksCtr()
            navigationController?.pushViewController(ctr, animated: true)
        case "Base":
            let ctr = ViewController()
            navigationController?.pushViewController(ctr, animated: true)
        case "webController":
//            https://api.instagram.com/oauth/authorize/?client_id=696f3c4e2c4045fd90f60cb6022ad937&trapp://getToken&response_type=token
            let ctr = WebController(urlString: "https://api.instagram.com/oauth/authorize/?client_id=696f3c4e2c4045fd90f60cb6022ad937&redirect_uri=http://token.firstvar.com/get_token&response_type=token")
            
//            let ctr = WebController(urlString: "https://api.instagram.com/oauth/authorize/?client_id=696f3c4e2c4045fd90f60cb6022ad937&http://token.firstvar.com/get_token&response_type=code")
            
            navigationController?.pushViewController(ctr, animated: true)
            
        default:
            break
        }
    }
    
}

extension DemoListCtr
{
    class Cell: JoTableCell {
        let nameL = UILabel()
        override func addLayoutRules() {
            contentView.eelay = [[nameL,[ee.T.L.B.R,[10,10,-10,-10]]]]
        }
        
        override func mo_model_reload() {
            nameL.text = mo.model["name",""]
        }
    }
}
